﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GS.CMS.Entities;
using System.Data;

public partial class usercontrols_toplinksection : System.Web.UI.UserControl
{
    string strSessionMenu = "Menu";
    Category _Category = new Category();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindTopLink();
    }
    private void BindTopLink()
    {
        string html ="";
        try
        {
          
            string strCat = Request.QueryString["root"];
            string strSubCat = Request.QueryString["subcat"];
            string strSubCat0 = Request.QueryString["subcat0"];
            string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
            System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
            string sRet = oInfo.Name;
            html += "<a href=\"default.aspx\">Home</a> » ";
            if (sRet == "products-list.aspx")
            {
                if (strCat == "new")
                    html += "<a href=\"products-list.aspx?root=new\">New Products</a>";
                else if (strCat == "hotdeals")
                    html += "<a href=\"products-list.aspx?root=hotdeals\">Hot Deals</a>";
            }
            else if (sRet == "shopping-cart.aspx")
            {
                html += "<a href=\"shopping-cart.aspx\">Shopping Cart</a>";
            }
            else if (sRet == "category-list.aspx")
            {
                //Kiểm tra top link
                DataTable dtRoot = null, dtSub = null, dtSub0 = null;
                DataView dvRoot = null, dvSub = null, dvSub0 = null;
                DataTable dtMenu = (DataTable)Session[strSessionMenu];
                dvRoot = dtMenu.DefaultView;
                dvRoot.RowFilter = "CategoryID = '" + strCat + "'";
                dtRoot = dvRoot.ToTable();
                if (dtRoot != null && dtRoot.Rows.Count > 0)
                    html += string.Format("<a href=\"category-list.aspx?root={0}\">{1}</a>", strCat, dtRoot.Rows[0]["Name"]);
                if (!string.IsNullOrEmpty(strSubCat))
                {
                    dvSub = dtMenu.DefaultView;
                    dvSub.RowFilter = "CategoryID = '" + strSubCat + "'";
                    dtSub = dvSub.ToTable();
                    html += string.Format(" » <a href=\"category-list.aspx?root={0}&subcat={1}\">{2}</a>", strCat, strSubCat, dtSub.Rows[0]["Name"]);
                }
                if (!string.IsNullOrEmpty(strSubCat0))
                {
                    dvSub0 = dtMenu.DefaultView;
                    dvSub0.RowFilter = "CategoryID = '" + strSubCat0 + "'";
                    dtSub0 = dvSub0.ToTable();
                    html += string.Format(" » <a href=\"category-list.aspx?root={0}&subcat={1}&subcat0={2}\">{3}</a>", strCat, strSubCat, strSubCat0, dtSub0.Rows[0]["Name"]);
                }
            }
            else if (sRet == "product-detail.aspx")
            {
                //Kiểm tra nếu có category
                string strDetailSubCat = Request.QueryString["subcat0"];
                if (!string.IsNullOrEmpty(strDetailSubCat))
                {
                    DataTable dtCategory = _Category.GetCategoryByCategoryID(strDetailSubCat);
                    if (dtCategory != null)
                    {
                        html += string.Format("<a href=\"category-list.aspx?root={0}\">{1}</a>", dtCategory.Rows[0]["RootCat"] + "", dtCategory.Rows[0]["NameRoot"] + "");
                        html += string.Format(" » <a href=\"category-list.aspx?root={0}&subcat={1}\">{2}</a>", dtCategory.Rows[0]["RootCat"] + "", dtCategory.Rows[0]["SubCat"] + "",
                            dtCategory.Rows[0]["Name"] + "");
                        html += string.Format(" » <a href=\"category-list.aspx?root={0}&subcat={1}&subcat0={2}\">{3}</a>", dtCategory.Rows[0]["RootCat"] + "", dtCategory.Rows[0]["SubCat"] + "", dtCategory.Rows[0]["SubCat0"],
                           dtCategory.Rows[0]["Name0"] + "");
                    }
                }
            }
            lblTopLink.Text = html;
        }
        catch (Exception ex)
        {
            TrackingError.AddTrackingError("Author: sanghv - Funtion: BindData - Usercontrol:usercontrols_statusproducts", ex.Message);
        }
    }
}